package com.jyq.jsp.servlet;

import com.jyq.jsp.bean.UserBean;
import com.jyq.jsp.utils.ServletUtils;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @author Jiang Yongqiang
 */
public class BeanServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        UserBean userBean = new UserBean();
        try {
            BeanUtils.populate(userBean, request.getParameterMap());
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }


        request.setAttribute("userBean", userBean);
        ServletUtils.setAttribute(request,"userBean",userBean);
        ServletUtils.forward(request,response,"/jsp/bean_test.jsp");
    }
}
